from lxml import etree
import time
import requests
import os

root = "./images"
if not os.path.exists(root):
    os.mkdir(root)
thumb_root = os.path.join(root,'thumb_images')
print(thumb_root)
if not os.path.exists(thumb_root):
    os.mkdir(thumb_root)


res = requests.get("https://www.hdbz.net/")
content = res.content.decode()
# print(content)
html = etree.HTML(content)
# print(html)
as1 = html.xpath('//a[@class="item"]')

# print(html2)
for i in as1:
    html2 = i.xpath('.//img[@class="lazy"]/@data-original')
    names = i.xpath('.//div[@class="title"]/text()')
    print(i.tag)
    print(f'正在跑{names}')
    print(html2,type(html2))
    res = requests.get(html2[0])
    with open(f'{thumb_root}/{names[0]}.jpg', 'wb') as f:
        f.write(res.content)
    time.sleep(1)
















